import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main2 {


    public static List<Integer> list = new ArrayList<>();

    public static int n;

    public static int tempS = 1;

    public static int tempB;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        int[][] arr = new int[2][n]; //arr[0][i] 为酸，arr[1][i] 为苦
        for (int i = 0; i < n; i++) {
            arr[0][i] = sc.nextInt();
            arr[1][i] = sc.nextInt();
        }

        dfs(arr, 0);

        int ret = Integer.MAX_VALUE;

        for (int num : list) {
            // if (num > 1) {
            //     ret = Math.min(ret, num);
            // }
            ret = Math.min(ret, num);
        }

        System.out.println(ret);

        sc.close();
    }

    public static void dfs(int[][] arr, int k) {
        if (k == n) {
            if (tempS > 1 || tempB > 0) {
                list.add(Math.abs(tempS - tempB));
            }
            // list.add(Math.abs(tempS - tempB));
            return;
        }

        for (int i = k; i < n; i++) {
            //选
            tempS *= arr[0][i];
            tempB += arr[1][i];
            dfs(arr, i + 1);
            tempS /= arr[0][i];
            tempB -= arr[1][i];
            //不选
            dfs(arr, i + 1);
        }
    }
}